package com.sangeng.resolver;


import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
@Component
public class MyControllerAdvice {


    @ExceptionHandler({NullPointerException.class, ArrayIndexOutOfBoundsException.class})
    public ModelAndView handlerException(Exception e) {
        //出现了相关异常,就会调用该方法
        String message = e.getMessage();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg",message);
        modelAndView.setViewName("/WEB-INF/page/error.jsp");
        return modelAndView;
    }
}
